package io.nads.controller;

import io.nads.dto.Result;
import io.nads.entity.UserChatMessage;
import io.nads.service.ITTSService;
import io.nads.service.impl.TalkServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/talk")
@Slf4j
@RequiredArgsConstructor
public class TalkController {

    private final TalkServiceImpl talkService;
    private final ITTSService ittsService;

    /**
     * 用户与AI进行对话
     * @param chatSessionId 会话ID
     * @param audioFile 音频文件
     * @return 包含回复URL的结果对象
     */
    @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    public Result talk(@RequestParam("chat_session_id") Long chatSessionId,
                       @RequestParam("audio") MultipartFile audioFile) {
        return talkService.talk(chatSessionId, audioFile);
    }

    /**
     * 传递message获取语音的url
     * @param userChatMessage 音频文件
     * @return 包含回复URL的结果对象
     */
    @GetMapping(path = "/replay")
    public Result replay(UserChatMessage userChatMessage) {
        String voiceUrl = ittsService.getVoiceUrl(userChatMessage);
        return Result.ok(voiceUrl);
    }
}
